def is_prime(num):
    if num < 2:
        return False
    for i in range(2, int(num ** 0.5) + 1):
        if num % i == 0:
            return False
    return True

def find_largest_prime(num):
    num_str = str(num)
    primes = []
    
    for i in range(1, 1 << len(num_str)):
        prime_str = ''
        for j in range(len(num_str)):
            if i & (1 << j):
                prime_str += num_str[j]
        prime_num = int(prime_str)
        if is_prime(prime_num):
            primes.append(prime_num)

    if primes:
        return max(primes)
    else:
        return 0

num = int(input())
if 1000 <= num <= 9999:
    result = find_largest_prime(num)
    print(result)
else:
    print(0)
